<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
/**
 * 商品编码控制器
 */
class CodeController extends CommonController{
	/**
	 * 出库商品检索
	 */
	public function goodsLookup(){
        $this->search();
        $pageNum=I('pageNum',1,intval);//第几页
        $numPerPage=I('numPerPage',10,intval);//每页显示条数
        //获取排序的字段及排序方式
        $orderField=$_POST['_order']?$_POST['_order']:'id';
        $orderDirection=$_POST['_sort']?$_POST['_sort']:'asc';
        //组合排序字符串
        $orders=($orderField.' '.$orderDirection);
        //检索条件
        if($_POST['search_where']){
            $search_where=$_POST['search_where'];
            session('depot_id',$search_where['depot_id']['eq']);
            $this->assign('search_where',$search_where);
            $where=$this->_search();
        }else{
            $depot_id=session('depot_id');
            if(!empty($depot_id)){
                $where['depot_id']=array('eq',$depot_id);
            }else{
                $depots=session('depots');
                $where['depot_id']=array('in',$depots);
            }
        }
        //在where条件中增加未删除的判断条件
        $where['del']=array('eq','0');
        //在where条件中增加状态可用的判断条件
        $where['status']=array('eq','1');
        $db=D('codeView');
        $count=$db->where($where)->count();
        $this->assign('totalCount',$count);//数据的总条数
        $this->assign('numPerPage',$numPerPage);//每页显示多少条
        $this->assign('pageNumShown',6);//页标数字多少个
        $this->assign('currentPage',$pageNum);//当前是第几页
        $page= new \Think\Page($count,$numPerPage);
        $field=array('id','price','code','goods_name','xinghao','guige','depot_name','supplier_name');
        $this->list=$db->limit($numPerPage)->Page($pageNum)->order($orders)->field($field)->where($where)->select();
        $this->display();
	}
}